﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using CH.Study.ConsoleApp.ExpressionTree;
using System.Data;
using System.Configuration;

namespace CH.Study.ConsoleApp
{
    #region 接口
    public interface ITest 
    {
        void Start();
    }
    #endregion
    #region 通用方法
    public class Common
    {
        public static void Write(string str)
        {
            string file = AppDomain.CurrentDomain.BaseDirectory + @"\test.txt";
            FileStream fs = new FileStream(file, FileMode.Append);
            StreamWriter sw = new StreamWriter(fs);
            sw.WriteLine(str);
            sw.Close();
            sw.Dispose();
            fs.Close();
            fs.Dispose();
        }

    }
    #endregion
    #region 测试数据
    public class TestData
    {
        public static readonly string CONNECTION_STRING = ConfigurationManager.AppSettings["MsSql2005"];

        #region data
        public static List<Student> students = new List<Student>
        {
            new Student {FirstName = "Terry", LastName = "Adams", ID = 120, 
                Year = GradeLevel.SecondYear, 
                ExamScores = new List<int>{ 99, 82, 81, 79}},
            new Student {FirstName = "Fadi", LastName = "Fakhouri", ID = 116, 
                Year = GradeLevel.ThirdYear,
                ExamScores = new List<int>{ 99, 86, 90, 94}},
            new Student {FirstName = "Hanying", LastName = "Feng", ID = 117, 
                Year = GradeLevel.FirstYear, 
                ExamScores = new List<int>{ 93, 92, 80, 87}},
            new Student {FirstName = "Cesar", LastName = "Garcia", ID = 114, 
                Year = GradeLevel.FourthYear,
                ExamScores = new List<int>{ 97, 89, 85, 82}},
            new Student {FirstName = "Debra", LastName = "Garcia", ID = 115, 
                Year = GradeLevel.ThirdYear, 
                ExamScores = new List<int>{ 35, 72, 91, 70}},
            new Student {FirstName = "Hugo", LastName = "Garcia", ID = 118, 
                Year = GradeLevel.SecondYear, 
                ExamScores = new List<int>{ 92, 90, 83, 78}},
            new Student {FirstName = "Sven", LastName = "Mortensen", ID = 113, 
                Year = GradeLevel.FirstYear, 
                ExamScores = new List<int>{ 88, 94, 65, 91}},
            new Student {FirstName = "Claire", LastName = "O'Donnell", ID = 112, 
                Year = GradeLevel.FourthYear, 
                ExamScores = new List<int>{ 75, 84, 91, 39}},
            new Student {FirstName = "Svetlana", LastName = "Omelchenko", ID = 111, 
                Year = GradeLevel.SecondYear, 
                ExamScores = new List<int>{ 97, 92, 81, 60}},
            new Student {FirstName = "Lance", LastName = "Tucker", ID = 119, 
                Year = GradeLevel.ThirdYear, 
                ExamScores = new List<int>{ 68, 79, 88, 92}},
            new Student {FirstName = "Michael", LastName = "Tucker", ID = 122, 
                Year = GradeLevel.FirstYear, 
                ExamScores = new List<int>{ 94, 92, 91, 91}},
            new Student {FirstName = "Eugene", LastName = "Zabokritski", ID = 121,
                Year = GradeLevel.FourthYear, 
                ExamScores = new List<int>{ 96, 85, 91, 60}}
        };

        public static DataTable Members
        {
            get
            {
                string sql = "select * from Member";
                DataSet ds = DbSqlHelper.ExecuteDataSet(CONNECTION_STRING, CommandType.Text, sql);
                return ds.Tables[0];
            }
        }

        #endregion
    }
    #endregion
    #region 实体


    public class Student
    {
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public int ID { get; set; }
        public GradeLevel Year;
        public List<int> ExamScores;
    }
    public class Member
    {
        public int ID { get; set; }
        public virtual string Name { get; set; }
        public virtual string Email { get; set; }
        public virtual int Age { get; set; }
        public virtual DateTime AddTime { get; set; }
        public virtual int Level { get; set; }
    }



    #endregion
    #region 枚举
    public enum GradeLevel { FirstYear = 1, SecondYear, ThirdYear, FourthYear };
    #endregion
    #region 扩展方法
    public static class Ext
    {
        public static void FormatWriteLine(this string format, params object[] args)
        {
            Console.WriteLine(string.Format(format, args));
        }
    }
    #endregion
}
